package com.yamaikj.feign;

import feign.hystrix.FallbackFactory;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class GoodsServiceHystric implements FallbackFactory<GoodsServiceFeign> {

    private static final Logger LOG = LoggerFactory.getLogger(GoodsServiceHystric.class);
    public static final String ERR_MSG = "Test接口暂时不可用: ";

    @Override
    public GoodsServiceFeign create(Throwable throwable) {
        String msg = throwable == null ? "" : throwable.getMessage();
        if (!StringUtils.isEmpty(msg)) {
            LOG.error(msg);
        }
        return new GoodsServiceFeign() {
            @Override
            public String save() {
                String errer = ERR_MSG;
                return errer;
            }
        };
    }
}
